package com.cw.jeeyt.dao.impl.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.cw.jeeyt.dao.intf.system.SystemDatabaseTableDao;
import com.cw.jeeyt.dao.mapper.system.SystemDatabaseTableMapper;
import com.cw.jeeyt.dao.model.system.SystemDatabaseTableDo;
import com.cw.lang.common.utils.PageUtil;
import com.cw.lang.common.pagehelper.PageHelper;
import com.cw.lang.mybatis.dto.PageInfo;

/**
 * 数据库表信息 dao数据库操作接口
 *
 * @author chenw
 * @version 1.0.0
 */
@Repository
public class SystemDatabaseTableDaoImpl implements SystemDatabaseTableDao {
    @Autowired
    private SystemDatabaseTableMapper systemDatabaseTableMapper;

    /**
     * 查询所有数据库表信息
     *
     * @return 数据库表信息集合
     */
    @Override
    public List<SystemDatabaseTableDo> querySystemDatabaseTableList() {
        return systemDatabaseTableMapper.querySystemDatabaseTableList();
    }

    /**
     * 删除数据库表信息
     *
     * @param systemDatabaseTable
     */
    @Override
    public void deleteSystemDatabaseTable(SystemDatabaseTableDo systemDatabaseTable) {
        systemDatabaseTableMapper.deleteSystemDatabaseTable(systemDatabaseTable);
    }

    /**
     * 修改数据库表信息
     *
     * @param systemDatabaseTable
     */
    @Override
    public void updateSystemDatabaseTable(SystemDatabaseTableDo systemDatabaseTable) {
        systemDatabaseTableMapper.updateSystemDatabaseTable(systemDatabaseTable);
    }

    /**
     * 根据主键查询数据库表信息
     *
     * @param id 主键id
     * @return SystemDatabaseTable
     */
    @Override
    public SystemDatabaseTableDo getSystemDatabaseTableById(String id) {
        return systemDatabaseTableMapper.getSystemDatabaseTableById(id);
    }

    /**
     * 新增数据库表信息
     *
     * @param systemDatabaseTable
     * @return 整数
     */
    @Override
    public Integer insertSystemDatabaseTable(SystemDatabaseTableDo systemDatabaseTable) {
        return systemDatabaseTableMapper.insertSystemDatabaseTable(systemDatabaseTable);
    }

    /**
     * 分页查询数据库表信息
     *
     * @param systemDatabaseTable 查询条件
     * @param startNum 开始条数
     * @param pageSize 每页长度
     * @return SystemDatabaseTable集合
     */
    @Override
    public PageInfo<SystemDatabaseTableDo> queryByPage(SystemDatabaseTableDo systemDatabaseTable, Integer startNum,
        Integer pageSize) {
        PageHelper.startPage(PageUtil.calPageNum(startNum, pageSize), pageSize);
        return new PageInfo<>(systemDatabaseTableMapper.queryByPage(systemDatabaseTable));
    }

    /**
     * 根据数据库id查询表信息
     *
     * @param databaseId
     * @return
     * @throws Exception
     */
    @Override
    public List<SystemDatabaseTableDo> queryListByDatabaseId(String databaseId) {
        return systemDatabaseTableMapper.queryListByDatabaseId(databaseId);
    }

    /**
     * 根据数据库id删除表信息
     *
     * @param databaseId
     * @throws Exception
     */
    @Override
    public void deleteByDatabaseId(String databaseId) {
        systemDatabaseTableMapper.deleteByDatabaseId(databaseId);
    }

    /**
     * 根据表编码、表名称查询数据库表信息是否已经存在
     *
     * @param tableCode
     * @param tableName
     * @return
     * @throws Exception
     */
    @Override
    public SystemDatabaseTableDo checkSystemDatabaseTable(String tableCode, String tableName, String databaseCode) {
        return systemDatabaseTableMapper.checkSystemDatabaseTable(tableCode, tableName, databaseCode);
    }

    /**
     * 查询要同步的数据库表信息
     *
     * @param systemDatabaseTable
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<SystemDatabaseTableDo> querySyncByPage(SystemDatabaseTableDo systemDatabaseTable, Integer startNum,
        Integer pageSize) {
        PageHelper.startPage(PageUtil.calPageNum(startNum, pageSize), pageSize);
        return new PageInfo<>(systemDatabaseTableMapper.querySyncByPage(systemDatabaseTable));
    }

    /**
     * 根据表前缀删除数据库表信息
     *
     * @param tablePrefix
     */
    @Override
    public void deleteByTableCodePrefix(String tablePrefix, String modulePrefix) {
        systemDatabaseTableMapper.deleteByTableCodePrefix(tablePrefix, modulePrefix);
    }
}
